package net.zjitc.dao;

import net.zjitc.po.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by Administrator on 2017/12/18.
 */
public class UserDaoImpl implements UserDao{

    SqlSessionFactory factory;

    public UserDaoImpl(SqlSessionFactory factory) {
        this.factory = factory;
    }

    public User findUserById(int id) throws IOException {
        /*1.读文件，生成工厂
        * 2.工厂生成会话
        * 3.会话执行语句
        * 4.关闭会话
        * */

        SqlSession sqlSession = factory.openSession();
        User user = sqlSession.selectOne("test.findUserById", id);
        return user;
    }

}
